import javax.swing.*;
import java.awt.*;

public class Tile
{
    private boolean occupied; // is this tile occupied?
    private boolean mine = false; // checks if the tile has a mine on it
    private int x, y; // posisiton on the 2D array
    private int posX, posY; // actual position
	private char type; // type of tile
    private LoadTile tileLoader; // the object that created all the tiles

    Image img; // the image of the tile

	public Tile (int x, int y, char type, LoadTile tileLoader)
	{
	    this.x = x; // array x
	    this.y = y; // array y
	    this.posX = x * 16; // x
	    this.posY = y * 16; // y
	    this.type = type; // type
	    this.tileLoader = tileLoader; // tileLoader

		if (type == 'T')  // Image tile for trees
			this.img = tileLoader.getTree();
		else if (type == 'W')  // Image tile for walls
			this.img = tileLoader.getWall();
		else if (type == 'M')  // Image tile for minerals
			this.img = tileLoader.getMineral();
		else if (type == 'R')  // Image tile for ramps
			this.img = tileLoader.getRamp(); 
		else if (type == '0')  // Image tile for grass
			this.img = tileLoader.getGrass();
		else if (type == '1')  // Image tile for player one base
			this.img = tileLoader.getPlayerOneBase();
		else if (type == '2')  // Image tile for player two base
			this.img = tileLoader.getPlayerTwoBase();

		if (type == 'T' || type == 'W') // if its a tree or wall, the tile is occupied
			occupied = true;		
		else
			occupied = false;
	}

    // generic getters and setters
	public void setType (char type)
	{
		this.type = type;
	}

	public char getType()
	{
		return type;
	}

	public void setOccupied(boolean occupied)
	{
		this.occupied = occupied;
	}

	public boolean getOccupied()
	{
		return occupied;
	}

	public boolean getMine()
	{
		return this.mine;
	}
	
	public void setMine(boolean mine)
	{
		this.mine = mine;
	}
	
	public void setX(int x)
	{
		this.x = x;
	}

	public void setY(int y)
	{
		this.y = y;
	}

	public void setPosX(int posX)
	{
	this.posX = posX;
	}

	public void setPosY(int posY)
	{
		this.posY = posY;
	}

	public int getX()
	{
		return x;
	}

	public int getY()
	{
		return y;
	}

	public int getPosX()
	{
		return posX;
	}

	public int getPosY()
	{
		return posY;
	}

    // complicated! lets see. it changes the type of a tile, including all images and everything, as if it was never the old tile
	public void setTile(char type)
	{
	    this.type = type; // changes the type

		if (this.type == '0')
		{
		    if (type == 'T') // if the new type is a tree, img becomes tree
				this.img = tileLoader.getTree();
		    else if (type == 'W') // see above, wall
				this.img = tileLoader.getWall();
		    else if (type == '0') // see abvoe, grass
				this.img = tileLoader.getGrass();

		    // sets occupied level
			if (type == 'W' || type == 'T')
				occupied = true;
			else
				occupied = false;	
		}
		else if (this.type == 'M') // This gets invoked when a player walks over a mineral (coin). That coin dissapears and is replaced by grass.
			this.img = tileLoader.getGrass();
	}
}